	(function (jQuery) {
		
		jQuery.fn.tabelaOrdenada = function( aCamposTH, pCampo, pTipo, pQuerystring ) {
			
			var fQuerystring = '';
			if ( pQuerystring != undefined ) {
				fQuerystring = pQuerystring;
			}
			
			var _cgf_class_padrao = 'spOrdenacao';
			var _cfg_prefixo = 'spOrdenacao-';
			var _cfg_regex_prefixo = new RegExp( _cfg_prefixo, 'gi' );
			
			var _href = jQuery( location ).attr('href');
			_href = _href.split( '?' );
			_href = _href[0];
			
			var _Campo = pCampo;
			var _Tipo = pTipo;
			
			var $this = jQuery( this );
			var _aTH = $this.find( 'th' );
			
			var $aObjetos = new Array();
			
			var __campo = '';
			var __Obj = null;
			var __html = '';
			var __strObj = '';
			
			jQuery( aCamposTH ).each(function( _i ) {
				
				__campo = this + '';
				__campo = __campo.replace( /\./gi, '-' );
				__Obj = null;
				__html = '';
				
				try {
					
					__Obj = jQuery( _aTH[ _i ] );
					__html = __Obj.html();
					__strObj = '<span lang="desc" class="' + _cgf_class_padrao + '" id="' + _cfg_prefixo +  __campo + '">' + __html + '</span>';
					
					__Obj.html( '' );
					__Obj.append( __strObj );
					
					$aObjetos.push( __Obj.children( 'span' ) );
					
					
				} catch( ex ) {
					return false;
				}
				
			});
			
			var ___Campo = _Campo.replace( /\./gi, '-' );
			$( '#' + _cfg_prefixo + ___Campo ).addClass( _cgf_class_padrao + _Tipo.toUpperCase() ).attr( 'lang', _Tipo.toLowerCase() );
			
			jQuery( $aObjetos ).each(function() {
				var $this = jQuery( this );
				$this.bind( 'click', function() {
					
					var _id = $this.attr( 'id' );
					_id = _id.replace( _cfg_regex_prefixo, '' ).replace( /\-/gi, '.' );
					
					var _tipoOrd =  $this.attr( 'lang' ).toLowerCase();
					_tipoOrd = ( ( _tipoOrd.toLowerCase() == 'desc' ) ? 'asc' : 'desc' );
					
					var newHref = _href + '?' + 'oc=' + _id + '&ot=' + _tipoOrd + ( ( fQuerystring != '' ) ? ( '&' + fQuerystring  ): '' );
					
					window.location.href = newHref;
					
				});
			});
			
			return $this;
			
		}
		
	})(jQuery);